/* eslint-disable function-paren-newline */
/**
 * Created by mar105 on 2019-01-11.
 */
import React, { Component } from 'react';
import { Form, Row, Col, List, Button, Card, Checkbox, Select } from 'antd';
import ShowType from '../../Common/CommonComponent';
import styles from '../../../index.less';
import * as commonUtils from '../../../utils/utils';

const FormItem = Form.Item;

class SplitPaste extends Component {
  constructor(props) {
    super(props);
    this.state = {
      // expand: false,
    };
  }

  handleToggle = () => {
    this.props.onToggle();
  };

  render() {
    const {
      masterConfig, enabled, sBackProcessClassifyData, checkProcessClassifyData,
    } = this.props;
    let { masterData } = this.props;
    masterData = masterData === undefined ? {} : masterData;
    const expand = true;
    const { getFieldDecorator } = this.props.form;
    const { sAllPartsName } = masterData;
    let allPartsName = [];
    if (sAllPartsName !== undefined) {
      allPartsName = sAllPartsName.split(',');
    }
    const newConfig = {};
    if (commonUtils.isNotEmptyObject(masterConfig) && masterConfig.gdsconfigformslave.length > 0) {
      const filterConfig = masterConfig.gdsconfigformslave.filter(item => (item.sName.indexOf('dSumPQty') > -1 || item.sName.indexOf('sMaterialsName') > -1 || item.sName.indexOf('iPrintModePo') > -1 || item.sName.indexOf('iPositiveColor') > -1));
      filterConfig.forEach((childNew) => {
        const child = { ...childNew };
        child.bVisible = true;
        let enabledNew = (enabled && !child.bReadonly && !child.specialControl);
        if (child.iTag === 1) {
          enabledNew = false;
        } else if (child.iTag === 3) {
          enabledNew = true;
        }
        const sMemo = child.sName.toLowerCase().endsWith('memo');
        const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
        const showTypeProps = {
          form: this.props.form,
          getSqlDropDownData: this.props.getSqlDropDownData,
          handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
          getFloatNum: this.props.getFloatNum,
          onChange: this.props.onMasterChange,
          showConfig: child,
          formItemLayout: sMemo ? formItemLayout : {},
          textArea: sMemo,
          enabled: enabledNew,
          dataValue: masterData[child.sName],
          bTable: false,
        };
        newConfig[child.sName] = showTypeProps;
      });
    }
    return (
      <FormItem className={styles.searchMainForm}>
        {allPartsName.length > 0 && Object.keys(newConfig).length > 4 ?
          <List
            grid={{ column: 6 }}
            dataSource={allPartsName}
            size="small"
            className={styles.workerList}
            renderItem={(sPartsName, i) => (
              <Row style={{ height: expand ? 'auto' : '0', overflow: 'hidden' }}>
                <Col className={styles.sPartsName}>
                  <span>{sPartsName}</span>
                </Col>
                <Row className={styles.collapseWorker}>
                  <Col span={6} order={1} >
                    <ShowType {...newConfig[`dSumPQty${sPartsName}`]} />
                  </Col>

                  <Col span={6} order={2} >
                    <ShowType {...newConfig[`sMaterialsName${sPartsName}`]} />
                  </Col>
                  <Col span={10} order={3} >
                    <Row>
                      <Col span={14}>
                        <ShowType {...newConfig[`iPrintModePo${sPartsName}`]} />
                      </Col>
                      <Col span={9}>
                        <ShowType {...newConfig[`iPositiveColor${sPartsName}`]} />
                      </Col>
                    </Row>
                  </Col>
                  {i === 0 ?
                    <div className={styles.workOrderMain}>
                      <Button onClick={this.props.handleDataCreate}>生成数据</Button>
                    </div> : ''
                   }
                </Row>
                <Row>
                  <Col>
                    {sBackProcessClassifyData !== undefined && sBackProcessClassifyData !== '' ?
                      <List
                        grid={{ column: 6 }}
                        dataSource={sBackProcessClassifyData.filter(item => (item.sType !== '3' && (item.sPartsName === sPartsName || item.sPartsName === '')))}
                        size="small"
                        className={styles.workerList}
                        renderItem={item => (
                          <List.Item className={styles.workerListItem}>
                            <Card>
                              <Checkbox
                                checked={checkProcessClassifyData !== undefined && checkProcessClassifyData.filter(card => (card.sId === item.sId && card.sPartsName === sPartsName)).length > 0}
                                onChange={(e) => {
                                  this.props.handleProcessChange(e, item, sPartsName);
                                }}
                                title={item}
                              >
                                {item.sName}
                              </Checkbox>
                              <div id="sPartsName">
                                {checkProcessClassifyData !== undefined && checkProcessClassifyData.filter(card => (card.sId === item.sId && card.sPartsName === sPartsName)).length > 0 ?
                                  <FormItem>
                                    {getFieldDecorator(`${item.sId + sPartsName}`, {
                                    })(
                                      <Select
                                        showSearch
                                        filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                        onSelect={this.props.handleSelectChangeProcess.bind(this, `${item.sId + sPartsName}:sId,${item.sId + item.sName + sPartsName}:sProcessName,${item.sId + item.sType + sPartsName}:sType`)}
                                      >{this.props.handleA(item.sId)}
                                      </Select>)}
                                  </FormItem>
                                  : ''}
                              </div>
                            </Card>
                          </List.Item>
                        )}
                      />
                      : ''}
                  </Col>
                </Row>
              </Row>
          )}
          />
        : ''}
      </FormItem>
    );
  }
}

export default SplitPaste;
